package com.ruoyi.welder.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.welder.domain.WelderQualifications;
import com.ruoyi.welder.service.IWelderQualificationsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 焊工资质管理Controller
 * 
 * @author ruoyi
 * @date 2023-01-14
 */
@Controller
@RequestMapping("/welder/qualifications")
public class WelderQualificationsController extends BaseController
{
    private String prefix = "welder/qualifications";

    @Autowired
    private IWelderQualificationsService welderQualificationsService;

    @RequiresPermissions("welder:qualifications:view")
    @GetMapping()
    public String qualifications()
    {
        return prefix + "/qualifications";
    }

    /**
     * 查询焊工资质管理列表
     */
    @RequiresPermissions("welder:qualifications:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WelderQualifications welderQualifications)
    {
        startPage();
        List<WelderQualifications> list = welderQualificationsService.selectWelderQualificationsList(welderQualifications);
        return getDataTable(list);
    }

    /**
     * 导出焊工资质管理列表
     */
    @RequiresPermissions("welder:qualifications:export")
    @Log(title = "焊工资质管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WelderQualifications welderQualifications)
    {
        List<WelderQualifications> list = welderQualificationsService.selectWelderQualificationsList(welderQualifications);
        ExcelUtil<WelderQualifications> util = new ExcelUtil<WelderQualifications>(WelderQualifications.class);
        return util.exportExcel(list, "焊工资质管理数据");
    }

    /**
     * 新增焊工资质管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存焊工资质管理
     */
    @RequiresPermissions("welder:qualifications:add")
    @Log(title = "焊工资质管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WelderQualifications welderQualifications)
    {
        return toAjax(welderQualificationsService.insertWelderQualifications(welderQualifications));
    }

    /**
     * 修改焊工资质管理
     */
    @RequiresPermissions("welder:qualifications:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WelderQualifications welderQualifications = welderQualificationsService.selectWelderQualificationsById(id);
        mmap.put("welderQualifications", welderQualifications);
        return prefix + "/edit";
    }

    /**
     * 修改保存焊工资质管理
     */
    @RequiresPermissions("welder:qualifications:edit")
    @Log(title = "焊工资质管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WelderQualifications welderQualifications)
    {
        return toAjax(welderQualificationsService.updateWelderQualifications(welderQualifications));
    }

    /**
     * 删除焊工资质管理
     */
    @RequiresPermissions("welder:qualifications:remove")
    @Log(title = "焊工资质管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(welderQualificationsService.deleteWelderQualificationsByIds(ids));
    }
}
